In [1]:
import param
import pandas as pd 
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import panel as pn
import numpy as np
pn.extension()

import plotly.express as px

# make plots static
%matplotlib inline

x_data = 6*np.random.random(50)
y_data = np.sin(x_data)

# create a simple dataframe of animal ratings
# df = pd.DataFrame({'Animal':['Pig', 'Goat' ,'Sheep', 'Frog', 'Goat', 'Goat', 'Pig', 'Sheep', 
#                              'Octopus', 'Goat', 'Pig', 'Sheep', 'Octopus', 'Frog', 'Goat', 'Goat',
#                             'Pig', 'Pig', 'Sheep', 'Frog', 'Frog', 'Octopus', 'Octopus'], 
#                    'Rating':[3, 10, 3, 2, 9, 10, 4, 1, 
#                              1, 8, 5, 6, 2, 4, 10, 9,
#                             5, 5, 3, 2, 3, 1, 1]})
# df.to_csv('animals.csv')
# df = pd.read_csv('animals.csv')

url = 'https://raw.githubusercontent.com/aimalz/plasticc-explorer/master/animals.csv'
df = pd.read_csv(url)

df_pd = pd.DataFrame()
df_pd['x_vals'] = np.arange(10)
df_pd['y_vals'] = np.random.random(10)

# create a class containing an animal selector drop-down, various plots, and a data table output
class RatingsDashboard(param.Parameterized):
    
    # drop down selector widget containing the list of animals, with the default being 'Goat'
    Animal = param.ObjectSelector(default='Goat', objects=list(df.Animal.unique()))
    
    # create data set containing only the data applicable to the animal in the drop down selector
    def get_data(self):
        class_df = df[(df.Animal==self.Animal)].copy()
        return class_df
    
    # seaborn box plot for the chosen animal
    def box_view(self):
        data = self.get_data() 
        ax = sns.boxplot(data['Rating'])
        plt.close()
        return ax.figure
    
    # table of data for the chosen animal
    def table_view(self):
        data = self.get_data()
        return data
    
    # table of data for the chosen animal
<<<<<<< Updated upstream
    def plot_view(self):
        data = self.get_data()
        fig = px.scatter(x=x_data, y=y_data)
        #fig.show()
        return fig.show()
=======
    """def plot_view(self):
        data = self.get_data()
        fig = px.scatter(x=x_data, y=y_data)
        #fig.show()
        return fig.show()"""
    
    def select_row(self):
        row=0
        data = self.get_data()
        animal = data.iloc[0]['Animal']
        animal_to_number = {'Pig': 1, 'Goat':2 ,'Sheep':3, 
                            'Frog':4, 'Octopus':5}
        row = animal_to_number[animal]
        fig, ax = plt.subplots()
        ax.plot(df_pd['x_vals'], row*.8*df_pd['y_vals'], 'o')
        ax.set_xlabel('xxs')
        ax.set_ylim(0, row+1)
        plt.close()
        return ax.figure
>>>>>>> Stashed changes

# create an instance of the class
rd = RatingsDashboard(name='')

# create a title for the dashboard
dashboard_title = '# Animal Ratings Dashboard'

# create some text describing the dashboard
dashboard_desc = 'An example of a simple interactive HoloViz Panel dashboard using a'\
                 ' dummy data set of animal ratings.'

# create a dashboard, defining the layout as one column containing the
# dashboard title, dashboard description, 'Animal' drop down selector,
# box plot, and data table
dashboard = pn.Column(dashboard_title, 
                      dashboard_desc,   
                      rd.param,       # 'Animal' drop down selector
                      rd.select_row,  # data plot
                      rd.box_view,    # box plot
                      rd.table_view,   # data table
<<<<<<< Updated upstream
                      rd.plot_view   # data plot
=======
                      #rd.plot_view,   # data plot
>>>>>>> Stashed changes
                     )
<<<<<<< Updated upstream
<<<<<<< Updated upstream
<<<<<<< Updated upstream =======
In [ ]:
 
In [2]:
# show the dashboard with the data embedded 
# (for using in an html download of the notebook so that 
# no 'callback' is required from the browser to get the data)
dashboard.embed(max_opts = 2)
                                             
In [3]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
In [4]:
%matplotlib inline

sns.set(font_scale=1.3, style="ticks")
In [5]:
x_data = 6*np.random.random(50)
y_data = np.sin(x_data)
plt.plot(x_data, y_data, '.')
Out[5]:
[<matplotlib.lines.Line2D at 0x7f9266b4d890>]
>>>>>>> Stashed changes
<<<<<<< Updated upstream
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.
  warnings.warn(
=======
In [6]:
import plotly.express as px
fig = px.scatter(x=x_data, y=y_data)
fig.show()
>>>>>>> Stashed changes
<<<<<<< Updated upstream
In [2]:
# show the dashboard with the data embedded 
# (for using in an html download of the notebook so that 
# no 'callback' is required from the browser to get the data)
dashboard.embed(max_opts = 2)
  0%|          | 0/5 [00:00<?, ?it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 20%|██        | 1/5 [00:00<00:00,  8.94it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 40%|████      | 2/5 [00:00<00:00,  8.79it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 60%|██████    | 3/5 [00:00<00:00,  8.91it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

 80%|████████  | 4/5 [00:00<00:00,  8.73it/s]
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

                                             
/home/aimalz/Code/PLAsTiCC/ve3_plasticc/lib/python3.8/site-packages/seaborn/_decorators.py:36: FutureWarning:

Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation.

In [ ]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
In [ ]:
%matplotlib inline

sns.set(font_scale=1.3, style="ticks")
In [ ]:
x_data = 6*np.random.random(50)
y_data = np.sin(x_data)
plt.plot(x_data, y_data, '.')
In [ ]:
import plotly.express as px
fig = px.scatter(x=x_data, y=y_data)
fig.show()
In [7]:
from bokeh.models import ColumnDataSource, OpenURL, TapTool
from bokeh.plotting import figure, output_file, show

output_file("openurl.html")

p = figure(plot_width=400, plot_height=400,
           tools="tap", title="Click the Dots")

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
    ))

p.circle('x', 'y', color='color', size=20, source=source)

url = "http://www.colors.commutercreative.com/@color/"
taptool = p.select(type=TapTool)
taptool.callback = OpenURL(url=url)

show(p)
In [ ]: